package com.jack;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class SettingItem {

    private String name;
    private boolean value;

    public SettingItem(String name, boolean value) {
        this.name = name;
        this.value = value;
    }

    /*
     * name,value
     */
    public SettingItem(byte[] data) throws IOException {
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        DataInputStream dis = new DataInputStream(bais);

        name = dis.readUTF();
        value = dis.readBoolean();

        bais.close();
        dis.close();
    }

    /*
     * sequence,name,value,imagepath
     */
    public byte[] getBytes() throws IOException {
        byte[] data = null;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);

        dos.writeUTF(name);
        dos.writeBoolean(value);

        data = baos.toByteArray();
        baos.close();
        dos.close();
        return data;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setValue(boolean value) {
        this.value = value;
    }

    public boolean getValue() {
        return value;
    }

    public String toString() {
        return this.name + ":" + this.value + ":";
    }
}
